package mspbots.hubspot.client.core.contacts;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import mspbots.hubspot.common.QueryBody;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import javax.validation.Valid;
import java.util.List;

/**
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2020/3/31
 */
@RestController
@RequestMapping("contacts/{tenantId}")
@RequiredArgsConstructor
public class ContactsController {

    private final ContactsServiceImpl contactService;

    @PostMapping("batch/create")
    public Mono<JsonNode> batchCreate(@PathVariable Long tenantId, @Valid @RequestBody ContactCreateBody createBody) {
        return this.contactService.batchCreate(tenantId, createBody);
    }

    @PostMapping("batch/delete")
    public Flux<Object> batchDelete(@PathVariable Long tenantId, @RequestBody List<String> emails) {
        return this.contactService.batchDelete(tenantId, emails);
    }

    @PostMapping("batch/update")
    public Flux<JsonNode> batchUpdate(@PathVariable Long tenantId, @Valid @RequestBody List<ContactUpdateBody> updateBodies) {
        return this.contactService.batchUpdate(tenantId, updateBodies);
    }

    @GetMapping("properties")
    public Flux<JsonNode> properties(@PathVariable Long tenantId) {
        return this.contactService.properties(tenantId);
    }

    @PostMapping("properties/batch/create")
    public Flux<JsonNode> propertiesBatchCreate(@PathVariable Long tenantId,
                                                @Valid @RequestBody List<ContactPropertiesBody> contactPropertiesBodies) {
        return this.contactService.propertiesBatchUpdate(tenantId, contactPropertiesBodies);
    }

    @PostMapping("search")
    public Flux<JsonNode> search(@PathVariable Long tenantId, @Valid @RequestBody QueryBody queryBody) {
        return this.contactService.search(tenantId, queryBody);
    }

    @PutMapping("associations/create/{contactId}/{ticketId}")
    public Mono<JsonNode> associationsCreate(@PathVariable Long tenantId, @PathVariable Long contactId,
                                             @PathVariable Long ticketId) {
        return this.contactService.associationsCreate(tenantId, contactId, ticketId);
    }

}
